from datetime import datetime
from . import baseModel
from sqlalchemy import Column, String, Integer, DateTime, TEXT, ForeignKey
from sqlalchemy.orm import relationship


# 小说列表
class NovelList(baseModel):
    __tablename__ = "novel_list"
    id = Column(Integer, primary_key=True, comment='主键id')
    name = Column(String(255), comment='名字')
    author = Column(String(50), comment='作者')
    address = Column(String(255), comment='地址')
    create_time = Column(DateTime, default=datetime.now, comment='创建时间')
    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='更新时间')
    enable = Column(Integer, comment='是否开启', default=0)
    menu = relationship("NovelMenu", backref="NovelList")
    update_status = Column(Integer, comment='更新状态', default=0)
    # 在父表类中通过 relationship() 方法来引用子表的类集合


# 章节表
class NovelMenu(baseModel):
    __tablename__ = "novel_menu"
    id = Column(Integer, primary_key=True, comment='主键id')
    name = Column(String(255), comment='名字')
    order = Column(Integer, comment='章节')
    content = Column(TEXT, comment='内容')
    address = Column(String(255), comment='地址')
    drive_name = Column(String(255), comment='驱动名字')
    create_time = Column(DateTime, default=datetime.now, comment='创建时间')
    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='更新时间')
    novel_id = Column(Integer, ForeignKey('novel_list.id'))


# 书架表
class BookShelf(baseModel):
    __tablename__ = "book_shelf"
    id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
    created_date = Column(DateTime, default=datetime.now, comment='创建时间')
    last_use = Column(DateTime, default=datetime.now, comment='最后时间')
    user_id = Column(Integer, comment="用户ID")
    novel_id = Column(Integer, comment="小说ID")
    chapter_id = Column(Integer, comment="章节ID")
    private = Column(Integer, comment='私人 1 正常 2 私人', default=1)
    enable = Column(Integer, comment='是否开启', default=1)


class BookSource(baseModel):
    __tablename__ = "book_source"
    id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
    novel_id = Column(Integer, comment="小说ID")
    drive_name = Column(String(255), comment='驱动名字')
    name = Column(String(255), comment='名字')
    author = Column(String(50), comment='作者')
    address = Column(String(255), comment='地址')
    enable = Column(Integer, comment='是否开启', default=1)
    chapter = Column(Integer, comment="最新章节id")